// pages/Jcrwcl/Jcrwcl.js
import ajax from '../../utils/api.js';
var app = getApp()

Page({

    /**
     * 页面的初始数据
     */
    data: {
        tyurl:getApp().globalData.tyurl,
        daohang: [
            {name: "任务通知单"},
            {name: "委托检测书"},
            {name: "设备反馈问题"},
            {name: "任务受理书"},
            {name: "资料检测项目"},
            {name: "现场检测项目"},
            {name: "检测仪器"},
            {name: "其他数据"},   
            {name: "附件上传"},  
          ],
        zilList:[],
          currentActive:0,
          date: '',
          rwtzd:{},//获取任务通知单
          wtjcs:{},//获取委托检测书
          rwbooxList:{},//任务受理书-现场检测基础信息
          date:'',
          date2:'',
          date3:'',
          date4:'',
          zilList:[],//获取原始记录相关信息-资料检测项目
          zilList:{},//获取原始记录相关信息-资料检测项目
          xcList:[],//获取原始记录相关信息-现场检测项目
          xcList:{},//获取原始记录相关信息-现场检测项目
          jcyqList:[],//获取原始记录相关信息-检测仪器
          jcyqList:{},//获取原始记录相关信息-检测仪器
          gxqtsjList:{},//获取原始记录相关信息-其他数据
          gxqtsjList:[],//获取原始记录相关信息-其他数据
          urlObjshenhe:{},
    },
    switchNav: function (e){
        var cur = e.currentTarget.dataset.current;                       
        this.setData({
            currentActive: cur,
        })      
        if (cur == 1) {
            this.weituojiance()
        }if (cur == 3) {
            this.rwboox()
        }if (cur == 4) {
            this.Xczl()
        }if (cur == 5) {
            this.Jcxm()
        }if (cur == 6) {
            this.jcyq()
        }if (cur == 7) {
            this.gxqtsj()
        }
    },
    showUserInfo() {
        this.setData({
            userinfo: wx.getStorageSync('userinfo'),
        })
    },
    bindDateChange: function(e) {
        this.setData({
          date: e.detail.value
        })
      },
      bindDateChange2: function(e) {
        this.setData({
          date2: e.detail.value
        })
      },
      bindDateChange3: function(e) {
        this.setData({
          date3: e.detail.value
        })
      },
      bindDateChange4: function(e) {
        this.setData({
          date4: e.detail.value
        })
      },
      resolveValue01:function (e) {
        var _this = this;
      var zilList=_this.data.zilList
      var index=e.target.dataset.col1
      zilList[index].col1=e.detail.value
      _this.setData({
        zilList: zilList, 
      })
    },
    resolveValue02:function (e) {
        var _this = this;
      var zilList=_this.data.zilList
      var index=e.target.dataset.defaultval
      zilList[index].defaultval=e.detail.value
      _this.setData({
        zilList: zilList, 
      })
    },
    resolveValue03:function (e) {
        var _this = this;
      var zilList=_this.data.zilList
      var index=e.target.dataset.remark
      zilList[index].remark=e.detail.value
      _this.setData({
        zilList: zilList, 
      })
    },
      resolveValue:function (e) {
          var _this = this;
        var xcList=_this.data.xcList
        var index=e.target.dataset.col1
        xcList[index].col1=e.detail.value
        _this.setData({
            xcList: xcList, 
	    })
      },
      resolveValue2:function (e) {
        var _this = this;
      var xcList=_this.data.xcList
      var index=e.target.dataset.col2
      xcList[index].col2=e.detail.value
      _this.setData({
          xcList: xcList, 
      })
    },
    resolveValue3:function (e) {
        var _this = this;
      var xcList=_this.data.xcList
      var index=e.target.dataset.col3
      xcList[index].col3=e.detail.value
      _this.setData({
          xcList: xcList, 
      })
    },
    resolveValue4:function (e) {
        var _this = this;
      var xcList=_this.data.xcList
      var index=e.target.dataset.defaultval
      xcList[index].defaultval=e.detail.value
      _this.setData({
          xcList: xcList, 
      })
    },
    resolveValue5:function (e) {
        var _this = this;
      var xcList=_this.data.xcList
      var index=e.target.dataset.remark
      xcList[index].remark=e.detail.value
      _this.setData({
          xcList: xcList, 
      })
    },
    resolveValue6:function (e) {
        var _this = this;
      var jcyqList=_this.data.jcyqList
      var index=e.target.dataset.col1
      jcyqList[index].col1=e.detail.value
      _this.setData({
        jcyqList: jcyqList, 
      })
    },
    resolveValue7:function (e) {
        var _this = this;
      var jcyqList=_this.data.jcyqList
      var index=e.target.dataset.col2
      jcyqList[index].col2=e.detail.value
      _this.setData({
        jcyqList: jcyqList, 
      })
    },
    resolveValue8:function (e) {
        var _this = this;
      var jcyqList=_this.data.jcyqList
      var index=e.target.dataset.col3
      jcyqList[index].col3=e.detail.value
      _this.setData({
        jcyqList: jcyqList, 
      })
    },
    resolveValue9:function (e) {
        var _this = this;
      var jcyqList=_this.data.jcyqList
      var index=e.target.dataset.defaultval
      jcyqList[index].defaultval=e.detail.value
      _this.setData({
        jcyqList: jcyqList, 
      })
    },
    resolveValue10:function (e) {
        var _this = this;
      var jcyqList=_this.data.jcyqList
      var index=e.target.dataset.effectivetime
      jcyqList[index].effectivetime=e.detail.value
      _this.setData({
        jcyqList: jcyqList, 
      })
    },
    resolveValue11:function (e) {
        var _this = this;
      var jcyqList=_this.data.jcyqList
      var index=e.target.dataset.remark
      jcyqList[index].remark=e.detail.value
      _this.setData({
        jcyqList: jcyqList, 
      })
    },
    qitashuju:function (e) {
        var _this = this;
      var gxqtsjList=_this.data.gxqtsjList
      var index=e.target.dataset.col1
      gxqtsjList[index].col1=e.detail.value
      _this.setData({
        gxqtsjList: gxqtsjList, 
      })
    },
    qitashuju2:function (e) {
        var _this = this;
      var gxqtsjList=_this.data.gxqtsjList
      var index=e.target.dataset.col2
      gxqtsjList[index].col2=e.detail.value
      _this.setData({
        gxqtsjList: gxqtsjList, 
      })
    },
    qitashuju3:function (e) {
        var _this = this;
      var gxqtsjList=_this.data.gxqtsjList
      var index=e.target.dataset.defaultVerdictVal
      gxqtsjList[index].defaultVerdictVal=e.detail.value
      _this.setData({
        gxqtsjList: gxqtsjList, 
      })
    },
    qitashuju4:function (e) {
        var _this = this;
      var gxqtsjList=_this.data.gxqtsjList
      var index=e.target.dataset.remark
      gxqtsjList[index].remark=e.detail.value
      _this.setData({
        gxqtsjList: gxqtsjList, 
      })
    },
      kaisijc(){//获取任务通知单
        var _this=this
        ajax.rwtzd(this.data.ids,{
        }).then((res)=>{
            _this.setData({
                rwtzd:res.data
            }) 
            } ).catch((err) => {
                console.log(err)
            });  
   },
   weituojiance(){//获取委托检测书
    var _this=this
    ajax.hqwtjcs(this.data.ids,{
    }).then((res)=>{
        _this.setData({
            wtjcs:res.data
        }) 
        } ).catch((err) => {
            console.log(err)
        });  
},
rwboox(){//任务受理书-现场检测基础信息
    var _this=this
    ajax.rwgl(this.data.ids,{
    }).then((res)=>{
        _this.setData({
            rwbooxList:res.data
        }) 
        } ).catch((err) => {
            console.log(err)
        });  
},
gengxinrwsls(){//更新任务受理书接口
    var _this=this
    ajax.gengxinrwsls(
        _this.data.form
    ).then((res)=>{
       
        } ).catch((err) => {
            console.log(err)
        });  
},
toLogin(e){//筛选
    var form=e.detail.value
    form.checkDate=this.data.date //检测日期
    form.nextCheckDate=this.data.date2 //下次定检时间
    form.putIntoDate=this.data.date3 //投入使用日期
    form.installDate=this.data.date4 //安装日期
    form.id = this.data.ids//id
    this.setData({
      form: form,
    })
    this.gengxinrwsls()
  },
  formzljc(e){//资料检测项目
      var form2 = e.detail.value
      form2.id = this.data.ids//id
    this.setData({
        form2: form2,
      })
      this.Xczl_post()
  },
  
  Xczl(){ //获取原始记录相关信息-资料检测项目
    var _this=this
    ajax.xczl(_this.data.ids).then((res)=>{
        _this.setData({
            zilList:res.data
        })
       
        } ).catch((err) => {
            console.log(err)
        });  
},
        Xczl_post(data){ //原始记录相关信息更新接口
            var _this=this
            // var tCheckRelationList=this.data.tCheckRelationList
            var zilList=this.data.xcList
            zilList=JSON.stringify(zilList);
            ajax.gengxinxx({
                data:zilList
            }).then((res)=>{
                wx.showToast({
                    title: '保存成功',
                    icon: 'success',
                    duration: 2000
                })
            } ).catch((err) => {
                    console.log(err)
                });  
        },
        Xczl_post2(data){ //原始记录相关信息更新接口
                var _this=this
                // var tCheckRelationList=this.data.tCheckRelationList
                var xcList=this.data.xcList
                xcList=JSON.stringify(xcList);
                ajax.gengxinxx({
                    data:xcList
                }).then((res)=>{
                    wx.showToast({
                        title: '保存成功',
                        icon: 'success',
                        duration: 2000
                    })
                } ).catch((err) => {
                        console.log(err)
                    });  
        },
        Xczl_post3(data){ //原始记录相关信息更新接口
            var _this=this
            // var tCheckRelationList=this.data.tCheckRelationList
            var jcyqList=this.data.jcyqList
            jcyqList=JSON.stringify(jcyqList);
            ajax.gengxinxx({
                data:jcyqList
            }).then((res)=>{
                wx.showToast({
                    title: '保存成功',
                    icon: 'success',
                    duration: 2000
                })
            } ).catch((err) => {
                    console.log(err)
                });  
    },
    Xczl_post4(data){ //原始记录相关信息更新接口
        var _this=this
        // var tCheckRelationList=this.data.tCheckRelationList
        var gxqtsjList=this.data.gxqtsjList
        gxqtsjList=JSON.stringify(gxqtsjList);
        ajax.gengxinxx({
            data:gxqtsjList
        }).then((res)=>{
            wx.showToast({
                title: '保存成功',
                icon: 'success',
                duration: 2000
            })
        } ).catch((err) => {
                console.log(err)
            });  
},
    
jcxm_form(e){//现场检测项目
    var form3 = e.detail.value
    form3.id = this.data.ids//id
  this.setData({
      form3: form3,
    })
    this.Xczl_post2()
},

Jcxm(){ //获取原始记录相关信息-现场检测项目
    var _this=this
    ajax.xcjcxm(_this.data.ids).then((res)=>{
        _this.setData({
            xcList:res.data
        })
       
        } ).catch((err) => {
            console.log(err)
        });  
},
jcyq(){//获取原始记录相关信息-检测仪器
    var _this=this
    ajax.gxjcyq(_this.data.ids).then((res)=>{
        _this.setData({
            jcyqList:res.data
        })
        } ).catch((err) => {
            console.log(err)
        });  
},
gxqtsj(){//获取原始记录相关信息-其他数据
    var _this=this
    ajax.gxqtsj(_this.data.ids).then((res)=>{
        _this.setData({
            gxqtsjList:res.data
        })
        } ).catch((err) => {
            console.log(err)
        });  
},
getfileimg: function (e) { //上传图片
    var _this = this;
      wx.chooseImage({
        count: 1,
        sizeType: ['original', 'compressed'],
        sourceType: ['album', 'camera'],
        success: function (res) {
          for(var i=0;i<=res.tempFilePaths.length;i++){
            wx.uploadFile({
              url: _this.data.tyurl+'system/file/upload/'+_this.data.ids+'/sourcerecord',
              filePath: res.tempFilePaths[i],
              name: 'files',
              header:{
                Authorization:wx.getStorageSync('token')
              },
              formData: {},
              success(res) {
                var _data = JSON.parse(res.data);
                // _this.jicekbxqList();
                _this.getFileList();
                
              }
            })
          }
        },
        fail: function (res) { console.log(res)},
        complete: function (res) {console.log(res) },
      }) 
  },
shenchu(e){
    var _this=this
    var id=e.currentTarget.dataset.id
    wx.showModal({
      title: '提示',
      content: '确认是否删除',
      success(res) {
        if (res.confirm) {
          ajax.shenchu({
            id:e.currentTarget.dataset.id
          }).then((res) => {
            // _this.jicekbxqList();
            _this.getFileList();
          }).catch((err) => {
            console.log(err)
          });
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
    
  },
  getFileList(){
    var _this=this
    ajax.getFileList(('system/file/getFileList/'+_this.data.ids+'/sourcerecord'),{
      
    }).then((res) => {
      console.log(res)
      this.setData({
        getFileList: res.data
      })
    }).catch((err) => {
      console.log(err)
    });
  },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
    if (options.ids){
            this.setData({
                ids:options.ids,
            })
            this.kaisijc()
        }
    if (options.urlObjshenhe){
            this.setData({
                urlObjshenhe:JSON.parse(options.urlObjshenhe),
            })
            console.log('urlObjshenhe',this.data.urlObjshenhe)
        }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.showUserInfo();
        this.getFileList();
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})